const express=require('express');
const multer=require('multer');
const router=express.Router();
const {addContent,selectContent,updates,updateInfo,deletes,classContent,}=require('../service/contentService')
let path = require('path');

let imgUrl=path.join(__dirname, '../public/images/');

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, imgUrl);
  },
  filename: function (req, file, cb) {
    cb(null, file.fieldname+Math.floor(Math.random()*10000)+ '.jpg');
  }
})
var upload=multer({storage:storage});
router.post('/upload',upload.single('wsvatar'),function(req,res,next){
  console.log(req.body);
  let file=req.file;
  console.log(file);
  res.send(file.filename);
})

router.post('/addContent',async function(req, res,next){
  let data = await addContent(req.body);
})

router.post('/selectContent',async function(req, res, next){
  let data = await selectContent(req.body);
  res.send(data); 
})

router.post('/update',async function(req, res, next){
  let data= await updates(req.body);
  res.send(data);
})

router.post('/updateInfo',async function(req, res, next){
  let data=await updateInfo(req.body);
})

router.post('/deletes',async function(req, res, next){
  let data=await deletes(req.body);
})

router.post('/classContent',async function(req, res, next){
  let data=await classContent(req.body);
  res.send(data);
})


module.exports =router;
